<?php

/**
 * This is the model class for table "comment".
 *
 * The followings are the available columns in table 'comment':
 * @property string $comment_id
 * @property string $author_id
 * @property string $text
 * @property string $publish_date
 * @property string $comment_flow_id
 *
 * The followings are the available model relations:
 * @property Blogpostcomment[] $blogpostcomments
 * @property Commentflow $commentFlow
 * @property User $author
 * @property Photocomment[] $photocomments
 * @property Videocomment[] $videocomments
 */
class Comment extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Comment the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'comment';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('author_id, text, comment_flow_id', 'required'),
			array('author_id, comment_flow_id', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('comment_id, author_id, text, publish_date, comment_flow_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'blogpostcomments' => array(self::HAS_MANY, 'Blogpostcomment', 'comment_id'),
			'commentFlow' => array(self::BELONGS_TO, 'Commentflow', 'comment_flow_id'),
			'author' => array(self::BELONGS_TO, 'User', 'author_id'),
			'photocomments' => array(self::HAS_MANY, 'Photocomment', 'comment_id'),
			'videocomments' => array(self::HAS_MANY, 'Videocomment', 'comment_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'comment_id' => 'Comment',
			'author_id' => 'Автор',
			'text' => 'Текст',
			'publish_date' => 'Дата',
			'comment_flow_id' => 'Comment Flow',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('comment_id',$this->comment_id,true);
		$criteria->compare('author_id',$this->author_id,true);
		$criteria->compare('text',$this->text,true);
		$criteria->compare('publish_date',$this->publish_date,true);
		$criteria->compare('comment_flow_id',$this->comment_flow_id,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}